package com.why.simpleboot.core.server.netty.handler;

import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpMethod;

/**
 * @program: why-simpleboot-framework
 * @description:
 * @author: @why
 * @create: 2021-05-22 14:33
 **/
public class HttpRequestHandlerChainFactory {
    private static RequestHandler get;
    private static RequestHandler post;
    static {
        get=new GetRequestHandler();
        post=new PostRequestHandler();
        get.setNextRequestHandler(post);

        //more request handler
    }
    private HttpRequestHandlerChainFactory() {

    }

    /**
     * 废弃
     * @param method
     * @return
     */
    @Deprecated
    public static RequestHandler getRequestHandler(HttpMethod method) {
        if (HttpMethod.GET == method) {
            return get;
        } else if (HttpMethod.POST == method) {
            return post;
        }
        return null;
    }

    /**
     * 没废弃
     * @param request
     * @return
     */
    public static FullHttpResponse handleRequestByChain(FullHttpRequest request) {
        return get.handle(request);
    }
}
